var e = require('../@babel/runtime/helpers/interopRequireDefault.js').default;
Object.defineProperty(exports, '__esModule', { value: !0 }),
  (exports.default = void 0);
var r = require('../@babel/runtime/helpers/classCallCheck.js'),
  t = require('../@babel/runtime/helpers/createClass.js'),
  a = e(require('A74E60C170B67DCFC12808C685DF0B27.js')),
  s = e(require('045FFEF070B67DCF623996F77EEF0B27.js')),
  n = (function () {
    function e() {
      r(this, e), (this.__placeImgeUrlHttps = 'https'), (this.customTag = {});
    }
    return (
      t(e, [
        {
          key: 'removeDoctype',
          value: function (e) {
            return e
              .replace(/<\?xml.*\?>\n/, '')
              .replace(/<.*!doctype.*\n/, '')
              .replace(/<.*!DOCTYPE.*\n/, '');
          },
        },
        {
          key: 'trimHtml',
          value: function (e) {
            return e
              .replace(/\r?\n+/g, '')
              .replace(/<!--.*?-->/gi, '')
              .replace(/\/\*.*?\*\//gi, '')
              .replace(/[ ]+</gi, '<');
          },
        },
        {
          key: 'definedCustomTag',
          value: function (e) {
            this.customTag = e;
          },
        },
        {
          key: 'getHtmlJson',
          value: function (e) {
            (e = this.removeDoctype(e)),
              (e = this.trimHtml(e)),
              (e = a.default.strDiscode(e));
            var r = this.customTag,
              t = [],
              n = { children: [] };
            return (
              (0, s.default)(e, {
                start: function (e, r, s) {
                  var i = { name: e };
                  0 !== r.length &&
                    (i.attrs = r.reduce(function (e, r) {
                      var t = r.name,
                        a = r.value;
                      return (
                        e[t]
                          ? Array.isArray(e[t])
                            ? e[t].push(a)
                            : (e[t] = [e[t], a])
                          : (e[t] = a),
                        e
                      );
                    }, {})),
                    (i.attrs = Object.assign({}, i.attrs));
                  var l = i.attrs.hasOwnProperty('class');
                  if (
                    ((i.attrs.class = l
                      ? i.attrs.class + ' rich-' + i.name
                      : 'rich-' + i.name),
                    'img' === i.name)
                  ) {
                    var c = i.attrs.src;
                    '' === c[0] && c.splice(0, 1),
                      (c = a.default.urlToHttpUrl(c, this.__placeImgeUrlHttps)),
                      (i.attrs.src = c);
                  }
                  if (('source' === i.name && (n.source = i.attrs.src), s)) {
                    var u = t[0] || n;
                    void 0 === u.children && (u.children = []),
                      u.children.push(i);
                  } else t.unshift(i);
                },
                end: function (e) {
                  var a = t.shift();
                  if (
                    (a.name !== e &&
                      console.error('invalid state: mismatch end tag'),
                    'video' === a.name &&
                      n.source &&
                      ((a.attrs.src = n.source), delete n.source),
                    r.hasOwnProperty(a.name) && (a.name = r[a.name]),
                    0 === t.length)
                  )
                    n.children.push(a);
                  else {
                    var s = t[0];
                    void 0 === s.children && (s.children = []),
                      s.children.push(a);
                  }
                },
                chars: function (e) {
                  var r = { text: e, type: 'text' };
                  if (0 === t.length) n.children.push(r);
                  else {
                    var a = t[0];
                    void 0 === a.children && (a.children = []),
                      a.children.push(r);
                  }
                },
                comment: function (e) {},
              }),
              n
            );
          },
        },
      ]),
      e
    );
  })();
exports.default = n;
